﻿Partial Public Class SpecificationExplorer

    Public SpecExplorer As SpecExplorerNodeInfo


    Public aPLSpecRev As PL.MESSDK.SpecificationRevision_PL = Nothing
    Public aPLSpecValue As SystemBoxSDK.PL.MESSDK.SpecificationValue_PL = Nothing
    Public aPLSpecAttribute As SystemBoxSDK.PL.MESSDK.SpecificationAttribute_PL = Nothing
    Public aPLSpecTestRev As SystemBoxSDK.PL.MESSDK.SpecificationTestRevision_PL = Nothing
    Private aPL As PLBase

    'Public Enum SpecTreeListLevel
    '    Root = 0
    '    Specification = 1
    '    SpecRevisionOrValue = 2
    '    SpecAttributeOrTest = 3
    'End Enum

    Public Overridable Sub AfterViewRegistered(ByVal sender As Object, ByVal e As ViewOperationEventArgs)
        Dim view As GridView = CType(sender, GridControl).MainView
        Dim row As DataRow = view.GetFocusedDataRow()
        Dim detailview As GridView = DirectCast(e.View, GridView)

        CType(detailview.DataSource, DataView).AllowNew = aGridControl.AllowCreate
        CType(detailview.DataSource, DataView).AllowDelete = aGridControl.AllowDelete
        CType(detailview.DataSource, DataView).AllowEdit = aGridControl.AllowUpdate

        If Not row("TestEnabled") AndAlso detailview.Name = "SpecificationRevision/SpecificationTestRevision" Then
            CType(detailview.DataSource, DataView).AllowNew = False
            CType(detailview.DataSource, DataView).AllowDelete = False
            CType(detailview.DataSource, DataView).AllowEdit = False
            detailview.OptionsView.NewItemRowPosition = NewItemRowPosition.None

        End If

        If detailview.Name = "SpecificationRevision/SpecificationAttribute" AndAlso Not row("AttributeEnabled") Then
            CType(detailview.DataSource, DataView).AllowNew = False
            CType(detailview.DataSource, DataView).AllowDelete = False
            CType(detailview.DataSource, DataView).AllowEdit = False
            detailview.OptionsView.NewItemRowPosition = NewItemRowPosition.None

        End If

        If detailview.Name = "SpecificationRevision/SpecificationAttribute" AndAlso detailview.RowCount > 0 Then
            detailview.OptionsView.NewItemRowPosition = NewItemRowPosition.None
        End If

    End Sub

    Public Overridable Sub InitNewMasterRowSpecValue(ByVal sender As Object, ByVal e As InitNewRowEventArgs)
        Dim view As GridView = CType(sender, GridView)
        Dim row As DataRow = view.GetFocusedDataRow()
        aPLSpecValue = EditPanePL
        aPLSpecValue.SpecID_FK = SpecExplorer.ParentID



        aPLSpecValue.NewRecord(row)
    End Sub

    Public Overridable Sub InitNewRowSpecAttribute(ByVal sender As Object, ByVal e As InitNewRowEventArgs)
        Dim view As GridView = CType(sender, GridView)
        Dim row As DataRow = view.GetFocusedDataRow()

        aPLSpecAttribute.NewRecord(row)
    End Sub

    Public Overridable Sub DetailGridAfterLoad(ByVal sender As Object, ByVal e As EventArgs)
        Dim aGridExtPL As GridExtPL = DirectCast(sender, GridExtPL)

        If aGridExtPL.MetaDataTable.TableName.Contains("Attribute") AndAlso aGridExtPL.MetaDataTable.Rows.Count > 0 Then
            aGridExtPL.AllowCreate = False
        End If
    End Sub


#Region "SPECIFICATION REVISION"

    ''' <summary>
    ''' Initialise a new Specification Revision
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks>This is where the PL method NewRecord of child PLs are called based on Row TableName alias MQ Name </remarks>
    Public Overridable Sub InitNewDetailRowSpecRevision(ByVal sender As Object, ByVal e As InitNewRowEventArgs)
        Dim view As GridView = CType(sender, GridView)
        Dim row As DataRow = view.GetFocusedDataRow()


        If row.Table.TableName.Contains("SpecificationAttribute") Then
            If aPLSpecAttribute Is Nothing Then
                aPLSpecAttribute = New SystemBoxSDK.PL.MESSDK.SpecificationAttribute_PL()
            End If

            aPLSpecAttribute.NewRecord(row)

        ElseIf row.Table.TableName.Contains("SpecificationTestRevision") Then

            If aPLSpecTestRev Is Nothing Then
                aPLSpecTestRev = New SystemBoxSDK.PL.MESSDK.SpecificationTestRevision_PL()
            End If

            aPLSpecTestRev.NewRecord(row)
        End If
    End Sub

    ''' <summary>
    ''' Initialise a new Specification Revision
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks>This is where the PL method NewRecord of  the master Grid PL is called </remarks>
    Public Overridable Sub InitNewMasterRowSpecRevision(ByVal sender As Object, ByVal e As InitNewRowEventArgs)
        Dim view As GridView = CType(sender, GridView)
        Dim row As DataRow = view.GetFocusedDataRow()
        aPLSpecRev.SpecificationId_FK = SpecExplorer.ParentID
        aPLSpecRev.NewRecord(row)

    End Sub

    ''' <summary>
    ''' This routine will copy the focus Specification revision to a new revision.
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks> The new revision is by default the actual last not ACITIVATED revision plus (+) 1</remarks>
    Public Overridable Sub CopySpecRevisionToNewRevision(ByVal sender As Object, ByVal e As EventArgs)

        If NodeDataRow IsNot Nothing Then
            Try

                Dim specRevID As Guid = CType(NodeDataRow("KeyID"), Guid)
                Dim specID As Guid = CType(NodeDataRow("ParentID"), Guid)

                SystemBoxSDK.PL.MESSDK.SpecificationRevision_PL.CopyToNewSpecRevision(specRevID, specID)

                ReloadTree()
            Catch sqlex As System.Data.SqlClient.SqlException
                MessageWindow.ShowMessage(sqlex)
            End Try
        End If
    End Sub


    ''' <summary>
    ''' This method creates a New Specification Revision and Test are enabled for creation
    ''' </summary>
    ''' <param name="specificationID"></param>
    ''' <remarks>Used bsp:bsp_SpecificationRevision_Create </remarks>
    Private Sub CreateNewSpecRevision(ByVal specificationID As Guid)


    End Sub


    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Public Overridable Sub CreateNewSpecRevision(ByVal sender As Object, ByVal e As EventArgs)
        Dim sqlcmd As System.Data.SqlClient.SqlCommand = Nothing
        'tested BD 2014-03-24
        Try
            sqlcmd = MetaQuery.GetSPCmdByMetaName("bsp_SpecificationRevision_Create")


            sqlcmd.Parameters("@SpecID").Value = NodeDataRow("KeyID")
            sqlcmd.ExecuteReader(CommandBehavior.CloseConnection)
            ReloadTree()

        Catch ex As Exception
            Throw ex
        Finally
            If sqlcmd IsNot Nothing Then
                sqlcmd.Dispose()
            End If
        End Try

    End Sub


    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Public Overridable Sub ActivateSpecRevision(ByVal sender As Object, ByVal e As EventArgs)

        Try
            If NodeDataRow IsNot Nothing Then
                Dim specRevID As Guid = CType(NodeDataRow("KeyID"), Guid)

                SystemBoxSDK.PL.MESSDK.SpecificationRevision_PL.Activate(specRevID)

                ReloadTree(ReloadContext.AfterUpdate)
                aGridControl.ReloadGrid()
            End If
        Catch sqlex As System.Data.SqlClient.SqlException
            MessageWindow.ShowMessage(sqlex)
        End Try


    End Sub


    Public Overridable Sub UnActivateSpecRevision()

        Try
            If NodeDataRow IsNot Nothing Then

                SystemBoxSDK.PL.MESSDK.SpecificationRevision_PL.UnActivate(SpecExplorer.KeyID)

                ReloadTree(ReloadContext.AfterUpdate)
                aGridControl.ReloadGrid()
            End If
        Catch sqlex As System.Data.SqlClient.SqlException
            MessageWindow.ShowMessage(sqlex)
        End Try


    End Sub



#End Region




    '   SPECIFICATION TEST
    Public Overridable Sub InitNewRowSpecTestRevision(ByVal sender As Object, ByVal e As InitNewRowEventArgs)
        Dim view As GridView = CType(sender, GridView)
        Dim row As DataRow = view.GetFocusedDataRow()
        aPLSpecTestRev.NewRecord(row)
    End Sub

    Private Sub SpecificationTestRowClick(sender As Object, e As RowClickEventArgs)

    End Sub




    Public Overridable Sub SpecificationRevisionDetailRowClick(ByVal sender As Object, ByVal e As RowClickEventArgs)
        'Dim detailView As GridView = DirectCast(sender, GridView)
        'Dim parentView As GridView = CType(detailView.ParentView, GridView)

        'Dim currentRow As DataRow = detailView.GetFocusedDataRow()
        'Dim parentRow As DataRow = currentRow.GetParentRow(detailView.Name)

        Dim view As GridView = DirectCast(sender, GridView)
        Dim row As DataRow = view.GetFocusedDataRow()
        'Dim parentRow As DataRow = row.GetParentRow(view.Name)


        'If row.Table.TableName = "SpecificationTestRevision" Then
        '    If CBool(parentRow("TestEnabled")) Then
        '        If row IsNot Nothing AndAlso Not IsDBNull(row("IsCopy")) Then
        '            If CBool(row("IsCopy")) Then
        '                view.OptionsBehavior.ReadOnly = True
        '            Else
        '                view.OptionsBehavior.ReadOnly = False
        '            End If
        '        End If
        '    Else
        '        view.OptionsBehavior.ReadOnly = True
        '    End If
        'End If


        'If row.Table.TableName = "SpecificationAttribute" Then
        '    If CBool(parentRow("TestEnabled")) Then
        '        If row IsNot Nothing AndAlso Not IsDBNull(row("IsCopy")) Then
        '            If CBool(row("IsCopy")) Then
        '                view.OptionsBehavior.ReadOnly = True
        '            Else
        '                view.OptionsBehavior.ReadOnly = False
        '            End If
        '        End If
        '    Else
        '        view.OptionsBehavior.ReadOnly = True
        '    End If
        'End If


    End Sub

    Public Overridable Sub EnableSpecTestEditing(ByVal sender As Object, ByVal e As EventArgs)
       

        Try
            If NodeDataRow IsNot Nothing Then
                Dim specRevID As Guid = CType(NodeDataRow("SpecificationRevId"), Guid)

                SystemBoxSDK.PL.MESSDK.SpecificationRevision_PL.EnableTest(specRevID)

                ReloadTree()
            End If
        Catch sqlex As System.Data.SqlClient.SqlException
            MessageWindow.ShowMessage(sqlex)
        End Try
    End Sub



    Private Sub EnableSpecAttributeEditing()
        Try
            If NodeDataRow IsNot Nothing Then
                Dim specRevID As Guid = CType(NodeDataRow("SpecificationRevId"), Guid)

                SystemBoxSDK.PL.MESSDK.SpecificationRevision_PL.EnableTest(specRevID)

                ReloadTree()
            End If
        Catch sqlex As System.Data.SqlClient.SqlException
            MessageWindow.ShowMessage(sqlex)
        End Try

    End Sub





    Public Overridable Sub ReviseSpecTest(ByVal sender As System.Object, ByVal e As EventArgs)
        Dim view As GridView = CType(aGridControl.GridControl1.FocusedView, GridView)

        Dim aRow As DataRow
        For Each i As Integer In view.GetSelectedRows()
            aRow = CType(view.GetRow(i), DataRowView).Row
            If aRow IsNot Nothing Then
                If CInt(aRow("NbReference")) > 1 Then
                    If CBool((aRow("IsCopy"))) Then
                        Dim specTestRevID As Guid = CType(aRow("SpecificationTestRevId"), Guid)
                        Dim specTestID As Guid = CType(aRow("SpecificationTestId_FK"), Guid)
                        Try
                            SystemBoxSDK.PL.MESSDK.SpecificationTestRevision_PL.ReviseSpecTest(specTestRevID, specTestID)


                        Catch sqlex As System.Data.SqlClient.SqlException
                            MessageWindow.ShowMessage(sqlex)
                        End Try
                    End If
                Else
                    MessageWindow.ShowMessage("No need to Revise, this test is not reference more than once.")
                End If
            End If


        Next

        Dim aMt As MetaDataTable = DirectCast(DirectCast(view.DataSource, DataView).Table, MetaDataTable)
        aMt.Clear()
        aMt.FillBusinessApplicationData()
        view.RefreshData()
        ReloadTree(ReloadContext.AfterUpdate)
    End Sub

    Public Overridable Sub LimitSpecTest(ByVal sender As System.Object, ByVal e As EventArgs)
      Dim view As GridView = CType(aGridControl.GridControl1.FocusedView, GridView)

        Dim aRow As DataRow
        For Each i As Integer In view.GetSelectedRows()
            aRow = CType(view.GetRow(i), DataRowView).Row
            If aRow IsNot Nothing Then
                If CInt(aRow("NbReference")) > 1 Then
                    If CBool((aRow("IsCopy"))) Then
                        Dim specTestRevID As Guid = CType(aRow("SpecificationTestRevId"), Guid)
                        Dim specTestID As Guid = CType(aRow("SpecificationTestId_FK"), Guid)
                        Try
                            SystemBoxSDK.PL.MESSDK.SpecificationTestRevision_PL.LimitSpecTest(specTestRevID, specTestID)


                        Catch sqlex As System.Data.SqlClient.SqlException
                            MessageWindow.ShowMessage(sqlex)
                        End Try
                    End If
                Else
                    MessageWindow.ShowMessage("No need to Revise, this test is not reference more than once.")
                End If
            End If
        Next

        Dim aMt As MetaDataTable = DirectCast(DirectCast(view.DataSource, DataView).Table, MetaDataTable)
        aMt.Clear()
        aMt.FillBusinessApplicationData()
        view.RefreshData()
        ReloadTree(ReloadContext.AfterUpdate)
    End Sub

    Public Overridable Sub SpecTestContextMenuBeforePopup(sender As Object, e As EventArgs)
        Dim aMenu As GridViewMenu = CType(sender, GridViewMenu)
        Dim row As DataRow = aMenu.View.GetFocusedDataRow()

        If row IsNot Nothing Then

            Dim i As Integer = 0
            For Each item As DXMenuItem In aMenu.Items
                If (item.Caption.Contains("Revise") Or item.Caption.Contains("Limit")) AndAlso Not CBool(row("IsCopy")) Then
                    item.Enabled = False
                End If
                If TypeOf item Is DXSubMenuItem Then
                    For Each subitem As DXMenuItem In CType(item, DXSubMenuItem).Items
                        If (subitem.Caption.Contains("Revise") Or subitem.Caption.Contains("Limit")) AndAlso Not CBool(row("IsCopy")) Then
                            subitem.Enabled = False
                        End If
                    Next
                End If
            Next
        End If
    End Sub

    Public Overridable Sub SpecTestRevisionValidate(ByVal sender As Object, ByVal e As Views.Base.ValidateRowEventArgs)
        Dim aView As GridView = CType(sender, GridView)
        Dim row As DataRow = aView.GetFocusedDataRow()

        If aPLSpecTestRev IsNot Nothing AndAlso row IsNot Nothing Then
            aPLSpecTestRev.ValidateRow(row)
        End If
    End Sub


    'TO BE REMOVED
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Public Overridable Sub RemoveSpecRevision(ByVal sender As Object, ByVal e As EventArgs)
        Dim sqlcmd As System.Data.SqlClient.SqlCommand = Nothing
        Try
            If NodeDataRow IsNot Nothing Then
                sqlcmd = MetaQuery.GetSPCmdByMetaName("bsp_SpecificationRevision_PL_Delete")
                sqlcmd.Parameters("@SpecificationRevId").Value = DirectCast(NodeDataRow("KeyID"), Guid)
                sqlcmd.ExecuteReader(CommandBehavior.CloseConnection)

            End If
        Catch sqlex As System.Data.SqlClient.SqlException
            MessageWindow.ShowMessage(sqlex)
        Finally
            If sqlcmd IsNot Nothing Then
                sqlcmd.Dispose()
            End If
        End Try

        ReloadTree(ExplorerTreeList.ReloadContext.AfterDelete)
    End Sub

    Public Overridable Sub RemoveSpec(ByVal sender As Object, ByVal e As EventArgs)
        Dim sqlcmd As System.Data.SqlClient.SqlCommand = Nothing

        Try
            If NodeDataRow IsNot Nothing Then
                sqlcmd = MetaQuery.GetSPCmdByMetaName("bsp_Specification_RemoveAll")
                sqlcmd.Parameters("@SpecId").Value = DirectCast(NodeDataRow("KeyID"), Guid)
                sqlcmd.ExecuteReader(CommandBehavior.CloseConnection)

            End If
        Catch sqlex As System.Data.SqlClient.SqlException
            MessageWindow.ShowMessage(sqlex)
        Finally
            If sqlcmd IsNot Nothing Then
                sqlcmd.Dispose()
            End If
        End Try

        ReloadTree()
    End Sub

    Public Overridable Sub Spec_ContextMenuBeforePopup(sender As Object, e As EventArgs)
        Dim aMenu As TreeListMenu = CType(sender, TreeListMenu)
        Dim row As DataRow = Me.aGridControl.GridView1.GetFocusedRow()


        If row IsNot Nothing Then
            Dim i As Integer = 0
            While i < aMenu.Items.Count
                If aMenu.Items(i).Caption.Contains("Activate") Then
                    If CBool(row("RevisionActivated")) Then
                        aMenu.Items(i).Enabled = False
                    End If

                ElseIf aMenu.Items(i).Caption.Contains("Enable") Then
                    If CBool(row("TestEnabled")) Then
                        aMenu.Items(i).Enabled = False
                    End If


                End If


                i += 1
            End While
        End If
    End Sub


    Public Overrides Sub LoadContextMenu()
        SpecExplorer = New SpecExplorerNodeInfo(NodeDataRow)
        MyBase.LoadContextMenu()

        Select Case SpecExplorer.QueryName

            Case "SpecificationList"
                SpecificationListActionOptionMenu()

            Case "Specification"
                SpecificationActionOptionMenu()

            Case "SpecificationRevision"
                SpecRevisionActionOptionMenu()

            Case "SpecificationValue"
                SpecAttributeActionOptionMenu()

            Case "SpecificationAttribute"
                SpecValueActionOptionMenu()

            Case "SpecificationTestRevision"
                SpecTestRevisionActionOptionMenu()
        End Select

        SpecExplorer.Dispose()

    End Sub

    Public Overridable Sub InitNewLayoutRow(sender As Object, e As InitNewRowEventArgs)
        Dim LayoutView As LayoutView = CType(sender, LayoutView)
        Dim row As DataRow = LayoutView.GetFocusedDataRow()
        Using Specification As SystemBoxSDK.PL.MESSDK.Specification_PL = New SystemBoxSDK.PL.MESSDK.Specification_PL()
            Specification.NewRecord(row)
        End Using
        row("Inactive") = 0
    End Sub

    Public Overridable Sub InitNewMasterRow(sender As Object, e As InitNewRowEventArgs)
        Dim view As GridView = CType(sender, GridView)
        Dim row As DataRow = view.GetFocusedDataRow()
        Using Spec As SystemBoxSDK.PL.MESSDK.Specification_PL = New SystemBoxSDK.PL.MESSDK.Specification_PL()
            Spec.NewRecord(row)
        End Using
    End Sub

    Private Sub Spec_InitNewMasterRow(sender As Object, e As InitNewRowEventArgs)
        Throw New NotImplementedException
    End Sub

    Private Sub ExplorerContextMenu(ByVal anode As TreeListNode)
        ' Throw New NotImplementedException
        Select Case SpecExplorer.QueryName

            Case "SpecificationList"
                SpecificationListActionOptionMenu()

            Case "Specification"
                SpecificationActionOptionMenu()

            Case "SpecificationRevision"
                SpecRevisionActionOptionMenu()

            Case "SpecificationValue"
                SpecAttributeActionOptionMenu()

            Case "SpecificationAttribute"
                SpecValueActionOptionMenu()

            Case "SpecificationTestRevision"


        End Select

    End Sub

    Private Sub SpecificationListActionOptionMenu()
        'If SpecExplorer IsNot Nothing Then
        '    Dim ItemActionOption As ActionOption
        '    Dim grpName As String = String.Empty


        '    For Each item As DXMenuItem In TreeContextMenu.Items
        '        ItemActionOption = item.Tag

        '        If ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (Not SpecExplorer.Approved) Then
        '            item.Enabled = False

        '        ElseIf ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (Not SpecExplorer.NodeActivated) Then
        '            '"UnActivate Revision"
        '            item.Enabled = False

        '        ElseIf ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (SpecExplorer.Approved OrElse SpecExplorer.NodeActivated) Then
        '            '"Delete Revision"
        '            item.Enabled = False

        '        Else
        '            item.Enabled = ItemActionOption.Enabled

        '        End If
        '    Next

        'End If
    End Sub
    ''' <summary>
    '''  Action menu For Specification 
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub SpecificationActionOptionMenu()
        If SpecExplorer IsNot Nothing Then
            Dim ItemActionOption As ActionOption
            Dim grpName As String = String.Empty


            For Each item As DXMenuItem In TreeContextMenu.Items
                ItemActionOption = item.Tag
                ' i would like to do a scan with nodeiterator to check if a DELETE is possible .....
                ' if no revison Acitvite 
                'if no value used BD 2014-10-17



                'If ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (SpecExplorer.Approved Or SpecExplorer.NodeActivated) Then
                '    '"Approve Revision "
                '    item.Enabled = False

                'ElseIf ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (Not SpecExplorer.Approved Or SpecExplorer.NodeActivated) Then
                '    '"Activate Revision"
                '    item.Enabled = False

                'ElseIf ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (Not SpecExplorer.NodeActivated) Then
                '    '"UnActivate Revision"
                '    item.Enabled = False

                'ElseIf ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (SpecExplorer.Approved OrElse SpecExplorer.NodeActivated) Then
                '    '"Delete Revision"
                '    item.Enabled = False

                'ElseIf ItemActionOption.OptionName.Equals("ACT_xxxxx") Then
                '    '"Copy to New Revision"


                'Else
                '    item.Enabled = ItemActionOption.Enabled

                'End If
            Next

        End If
    End Sub
    ''' <summary>
    ''' Action menu for  Specification Revision
    ''' 
    ''' </summary>
    ''' <remarks>
    ''' <table>
    '''  <tr>
    ''' <td>Activated</td> <td>TestEnabled</td> <td>AttributeEnabled</td>
    ''' </tr>
    ''' <tr><td>0</td> <td>0</td> <td>0</td>
    '''  </tr>
    ''' </table>
    ''' </remarks>
    ''' 
    Private Sub SpecRevisionActionOptionMenu()


        If SpecExplorer IsNot Nothing Then
            Dim ItemActionOption As ActionOption
            Dim grpName As String = String.Empty


            If SpecExplorer.RevisionActivated Then

            Else
                If SpecExplorer.TestEnabled Then

                End If

                If SpecExplorer.AttributeEnaled Then

                End If


            End If



            For Each item As DXMenuItem In TreeContextMenu.Items
                ItemActionOption = item.Tag

                If ItemActionOption.OptionName.Equals("ACT_00134") AndAlso (SpecExplorer.RevisionActivated) Then
                    '"Activate Revision "
                    item.Enabled = False

                ElseIf ItemActionOption.OptionName.Equals("ACT_00217") Then                    ' UnActivate Revision

                    If SpecExplorer.RevisionActivated AndAlso AppManager.IsPowerUser Then
                        item.Enabled = True
                    Else
                        item.Visible = False
                    End If

                    If SpecExplorer.RevisionActivated AndAlso Not (AppManager.IsPowerUser) Then
                        item.Visible = False
                    End If

                ElseIf ItemActionOption.OptionName.Equals("ACT_00079") AndAlso (SpecExplorer.RevisionActivated) Then
                    '"Delete Revision"
                    item.Enabled = False

                ElseIf ItemActionOption.OptionName.Equals("ACT_00082") AndAlso (SpecExplorer.RevisionActivated) Then
                    '"Delete Revision"
                    item.Enabled = False

                Else
                item.Enabled = ItemActionOption.Enabled

                End If
            Next

        End If


    End Sub

    Private Sub SpecAttributeActionOptionMenu()

        'If SpecExplorer IsNot Nothing Then
        '    Dim ItemActionOption As ActionOption
        '    Dim grpName As String = String.Empty


        '    For Each item As DXMenuItem In TreeContextMenu.Items
        '        ItemActionOption = item.Tag

        '        If ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (SpecExplorer.Approved Or SpecExplorer.NodeActivated) Then
        '            '"Approve Revision "
        '            item.Enabled = False

        '        ElseIf ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (Not SpecExplorer.Approved Or SpecExplorer.NodeActivated) Then
        '            '"Activate Revision"
        '            item.Enabled = False

        '        ElseIf ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (Not SpecExplorer.NodeActivated) Then
        '            '"UnActivate Revision"
        '            item.Enabled = False

        '        ElseIf ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (SpecExplorer.Approved OrElse SpecExplorer.NodeActivated) Then
        '            '"Delete Revision"
        '            item.Enabled = False

        '        ElseIf ItemActionOption.OptionName.Equals("ACT_xxxxx") Then
        '            '"Copy to New Revision"


        '        Else
        '            item.Enabled = ItemActionOption.Enabled

        '        End If
        '    Next

        'End If

    End Sub

    Private Sub SpecValueActionOptionMenu()
        'If SpecExplorer IsNot Nothing Then
        '    Dim ItemActionOption As ActionOption
        '    Dim grpName As String = String.Empty


        '    For Each item As DXMenuItem In TreeContextMenu.Items
        '        ItemActionOption = item.Tag

        '        If ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (SpecExplorer.Approved Or SpecExplorer.NodeActivated) Then
        '            '"Approve Revision "
        '            item.Enabled = False

        '        ElseIf ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (Not SpecExplorer.Approved Or SpecExplorer.NodeActivated) Then
        '            '"Activate Revision"
        '            item.Enabled = False

        '        ElseIf ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (Not SpecExplorer.NodeActivated) Then
        '            '"UnActivate Revision"
        '            item.Enabled = False

        '        ElseIf ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (SpecExplorer.Approved OrElse SpecExplorer.NodeActivated) Then
        '            '"Delete Revision"
        '            item.Enabled = False

        '        ElseIf ItemActionOption.OptionName.Equals("ACT_xxxxx") Then
        '            '"Copy to New Revision"


        '        Else
        '            item.Enabled = ItemActionOption.Enabled

        '        End If
        '    Next

        'End If


    End Sub

    Private Sub SpecTestRevisionActionOptionMenu()
        If SpecExplorer IsNot Nothing Then
            Dim ItemActionOption As ActionOption
            Dim grpName As String = String.Empty


            For Each item As DXMenuItem In TreeContextMenu.Items
                ItemActionOption = item.Tag

                If ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (SpecExplorer.NodeActivated) Then
                    '"Approve Revision "
                    item.Enabled = False

                ElseIf ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (SpecExplorer.NodeActivated) Then
                    '"Activate Revision"
                    item.Enabled = False

                ElseIf ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (Not SpecExplorer.NodeActivated) Then
                    '"UnActivate Revision"
                    item.Enabled = False

                ElseIf ItemActionOption.OptionName.Equals("ACT_xxxxx") AndAlso (SpecExplorer.NodeActivated) Then
                    '"Delete Revision"
                    item.Enabled = False

                ElseIf ItemActionOption.OptionName.Equals("ACT_xxxxx") Then
                    '"Copy to New Revision"


                Else
                    item.Enabled = ItemActionOption.Enabled

                End If
            Next

        End If


    End Sub


    Private Sub GetSpecificationTestRevision()
        Dim sqlcmd As System.Data.SqlClient.SqlCommand = Nothing

        Try
            If NodeDataRow IsNot Nothing Then
                sqlcmd = MetaQuery.GetSPCmdByMetaName("bsp_GetTestForSpecRevision")
                sqlcmd.Parameters("@SpecificationRevID").Value = DirectCast(NodeDataRow("KeyID"), Guid)
                sqlcmd.ExecuteReader(CommandBehavior.CloseConnection)

            End If
        Catch sqlex As System.Data.SqlClient.SqlException
            MessageWindow.ShowMessage(sqlex)
        Finally
            If sqlcmd IsNot Nothing Then
                sqlcmd.Dispose()
            End If
        End Try

        ReloadTree(ReloadContext.AfterUpdate)
    End Sub

    Private Sub ActionMenu_CopyToAnotherSpec()
        Try
            Me.Cursor = Cursors.WaitCursor

            Dim gridSP As GridExtSP = New GridExtSP("bsp_SpecRevision_CopyToAnotherSpec") With {.Dock = DockStyle.Fill}
            gridSP.SaveCMD = AddressOf Process_CopyToAnotherSpec
            AddHandler gridSP.AfterLoad, AddressOf AddRowParameter_CopyToAnotherSpec

            Dim aFrm As XtraForm = New XtraForm()
            If gridSP IsNot Nothing Then
                aFrm.MdiParent = Me.ParentForm
                aFrm.Controls.Add(gridSP)
                aFrm.Text = "<Text of SCREEN>"
                aFrm.Show()
                aFrm.Focus()
            End If

            Me.Cursor = Cursors.Default



        Catch sqlex As System.Data.SqlClient.SqlException
            MessageWindow.ShowMessage(sqlex)

        End Try

        ReloadTree(ReloadContext.AfterUpdate)
    End Sub


    Private Sub GetSpecificationTest()
        Try

            Me.Cursor = Cursors.WaitCursor

            Dim gridSP As GridExtSP = New GridExtSP("bsp_GetTestForSpecRevision") With {.Dock = DockStyle.Fill}
            gridSP.SaveCMD = AddressOf CopyTestForSpecTestRevision
            'AddHandler gridSP.AfterLoad, AddressOf AddRowParameter



            Dim aFrm As XtraForm = New XtraForm()
            If gridSP IsNot Nothing Then
                aFrm.MdiParent = Me.ParentForm
                aFrm.Controls.Add(gridSP)
                aFrm.Text = "Bla bla bla"
                aFrm.Show()
                aFrm.Focus()
            End If

            Me.Cursor = Cursors.Default
        Catch ex As Exception
            MessageWindow.ShowMessage(ex, MsgBoxStyle.Information)
        End Try


    End Sub


    Public Overridable Function CopyTestForSpecTestRevision(ByVal aMetaDataTable As MetaDataTable) As Boolean
        Try
            aMetaDataTable.ApplyChanges(continueUpdateOnError:=False, reload:=False)
            MessageWindow.ShowMessage("Successfully Copied.", MsgBoxStyle.Information)
            ReloadTree()
        Catch ex As Exception
            MessageWindow.ShowMessage(ex, MsgBoxStyle.Information)
        End Try
        Return True
    End Function


    Public Overridable Sub AddRowParameter(sender As Object, e As System.EventArgs)
        Try
            Dim aGrid As GridExtSP = CType(sender, GridExtSP)

            Dim arow As DataRow = aGrid.MetaDataTable.NewRow()
            'assign value for the metacolumn here

            arow("@ItemMasterRevID") = SpecExplorer.NodeID

            aGrid.MetaDataTable.Rows.Add(arow)

        Catch ex As Exception
            MessageWindow.ShowMessage(ex, MsgBoxStyle.Information)
        End Try
    End Sub

    Private Function Process_CopyToAnotherSpec(ByVal aMetaDataTable As MetaDataTable) As Boolean
        Try
            aMetaDataTable.ApplyChanges(continueUpdateOnError:=False, reload:=False)
            MessageWindow.ShowMessage("Successfull", MsgBoxStyle.Information)
            ReloadTree(ReloadContext.AfterUpdate)
        Catch ex As Exception
            MessageWindow.ShowMessage(ex, MsgBoxStyle.Information)
            Return False
        End Try
        Return True
    End Function

    Private Sub AddRowParameter_CopyToAnotherSpec(sender As Object, e As EventArgs)
        Try
            Dim aGrid As GridExtSP = CType(sender, GridExtSP)

            Dim arow As DataRow = aGrid.MetaDataTable.NewRow()
            'assign value for the metacolumn here

            arow("@SpecRevID") = SpecExplorer.KeyID
            aGrid.MetaDataTable.Rows.Add(arow)

        Catch ex As Exception
            MessageWindow.ShowMessage(ex, MsgBoxStyle.Information)
        End Try



    End Sub



End Class

Public Class SpecExplorerNodeInfo
    Inherits CommonExt.Utils.ExplorerNodeInfo


    'Refactor to CommonExt.Utils.ExplorerNodeInfo to be able to reused Mybase.Assign
    ' As per SStdPractice.   As SStdDesign.
    Public Property KeyID As Guid
    Public Property TestEnabled As Boolean
    Public Property AttributeEnaled As Boolean
    Public Property RevisionActivated As Boolean




    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub New(ByVal datarow As DataRow)
        MyBase.New(datarow)
    End Sub

    Public Overrides Sub Assign(ByVal datarow As DataRow)
        Try
            If Not IsDBNull(datarow("KeyID")) Then
                KeyID = CType(datarow("KeyID"), Guid)
            End If

            If Not IsDBNull(datarow("ParentID")) Then
                MyBase.ParentID = CType(datarow("ParentID"), Guid)
            End If

            If Not IsDBNull(datarow("MetaQuerie")) Then
                MyBase.QueryName = CType(datarow("MetaQuerie"), String)
            End If

            If Not IsDBNull(datarow("PL")) Then
                MyBase.PL = CType(datarow("PL"), String)
            End If

            If Not IsDBNull(datarow("TestEnabled")) Then
                TestEnabled = CType(datarow("TestEnabled"), String)
            End If

            If Not IsDBNull(datarow("AttributeEnabled")) Then
                AttributeEnaled = CType(datarow("AttributeEnabled"), String)
            End If

            If Not IsDBNull(datarow("RevisionActivated")) Then
                RevisionActivated = CType(datarow("RevisionActivated"), String)
            End If

        Catch ex As Exception
            MessageWindow.ShowMessage(ex.Message)
        End Try


    End Sub


End Class

